<?php

require_once ROOT_DIR.'models/TodoList.php';
require_once ROOT_DIR.'views/TodoListJSON.php';

/**
 * Retrieves a the list of TodoLists matching the parameters and echos the resulting view.
 * 
 * @param int $userID
 * @param boolean $public Default is false
 * @param int $from Default is 0
 * @param int $rows Default is 30
 * @param string $sort Default is 't'. Possible values are 't', 'cD'
 * @param string $order Default is 'asc'
 */
function getLists($userID = -1, $public = false, $from = 0, $rows = 30, $sort = 't', $order = 'asc'){
	
	if(is_null($public)) $public = false;
	if(is_null($userID) && !$public) $userID = $_SESSION['USER_ID'];
	else if(is_null($userID) && $public) $userID = -1;
	if(is_null($from)) $from = 0;
	if(is_null($rows)) $rows = 30;
	if(is_null($sort)) $sort = 't';
	if(is_null($order)) $order = 'asc';
	
	$lists = TodoList::getLists($userID, $public, $from, $rows, $sort, $order);
	$listCount = TodoList::getListCount($userID, $public);
	
	echo TodoListJSON::getView($lists, false, $listCount);
	
}

?>